#ifndef __PMEMORY_H__
#define __PMEMORY_H__
#include <common.h>
#include <dpic.h>

#define PMEM_BASE 0x80000000UL
#define PMEM_SIZE 0x10000000UL
#define PMEM_LEFT     PMEM_BASE
#define PMEM_RIGHT    PMEM_BASE + PMEM_SIZE - 1
#define RESET_VECTOR  PMEM_BASE
#define PAGE_SHIFT        12
#define PAGE_SIZE         (1ul << PAGE_SHIFT)
#define PAGE_MASK         (PAGE_SIZE - 1)


extern "C" void read_mem(long long, int, long long *);
extern "C" void write_mem(long long, int, long long);

static inline uint64_t host_read(void *addr, int len) {
  switch (len) {
    case 1: return *(uint8_t  *)addr;
    case 2: return *(uint16_t *)addr;
    case 4: return *(uint32_t *)addr;
    case 8: return *(uint64_t *)addr;
    default: assert(0);
  }
}

static inline void host_write(void *addr, int len, uint64_t data) {
  switch (len) {
    case 1: *(uint8_t  *)addr = data; return;
    case 2: *(uint16_t *)addr = data; return;
    case 4: *(uint32_t *)addr = data; return;
    case 8: *(uint64_t *)addr = data; return;
    default: assert(0);
  }
}

uint8_t* vaddr_to_paddr(uint64_t addr);
uint8_t* guest_to_host(uint64_t paddr);
uint64_t host_to_guest(uint8_t *haddr);

#else
#endif